﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EasyToHelp.Business;
using EasyToHelp.Entity;
using EasyToHelp.Service;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace EasyToHelp.WEBAPI.Controllers
{
    public class MemberController : BaseController
    {
        private readonly IMemberService Member;
        public MemberController(IMemberService _Member)
        {
            Member = _Member;
        }
        [EnableCors("CorsPolicy")]
        [HttpGet("MemberDo")]
        public object MemberDo(Member model, string action)
        {
            switch (action)
            {
                case "Add":
                    return Member.Add(model);
                case "Update":
                    return Member.Update(model);
                case "Delete":
                    return Member.Delete(model);
                case "GetList":
                    return Member.GetList();
                case "Edit":
                    return Member.Edit(model);
            }
            return null;
        }
        [HttpPost("Add")]
        [ProducesResponseType(typeof(Member), 201)]
        [ProducesResponseType(400)]
        public ActionResult Add([FromBody]Member value)
        {
            if (value == null) { return BadRequest(); }
            return Json(ResultInfo.Error(value.UserName));
            //return ResultInfo.Error(value.UserName);
            //var u = Member.GetList().Where(x => x.UserName == value.UserName).FirstOrDefault();
            //if (u!=null)
            //{
            //    return ResultInfo.Error("用户名已存在！");
            //}
            //if (Member.Add(value) >0)
            //{
            //    return ResultInfo.Success("注册成功！");
            //}
            //return ResultInfo.Error("注册失败！");
        }
    }
}